package cn.wolfcode.p2p.business.controller;


import cn.wolfcode.p2p.base.query.BidRequestQueryObject;
import cn.wolfcode.p2p.business.domain.BidRequest;
import cn.wolfcode.p2p.business.service.IBidRequestService;
import cn.wolfcode.p2p.util.Constant;
import cn.wolfcode.p2p.util.JSONResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 体验标对象
 */
@Controller
public class ExpBidRequestController {
    @Autowired
    private IBidRequestService bidRequestService;

    /**
     * 发布体验标页面
     */
    @RequestMapping("exp_bid_request_publish_page")
    public String expBidRequestPublishPage(Model model) {
        model.addAttribute("minBidRequestAmount", Constant.SMALLEST_BID_AMOUNT);
        model.addAttribute("minBidAmount", Constant.SMALLEST_BIDREQUEST_AMOUNT);
        return "expbidrequest/expbidrequestpublish";
    }

    /**
     * 发标
     */
    @RequestMapping("expBidRequestPublish")
    @ResponseBody
    public Object expBidRequestPublish(BidRequest bidRequest){
        bidRequestService.expBidRequestPublish(bidRequest);
        return JSONResultUtil.jsonResult();
    }

    /**
     * 体验标管理
     */
    @RequestMapping("expBidRequest_list")
    public String expBidRequestList(@ModelAttribute("qo")BidRequestQueryObject qo, Model model){
        qo.setBidRequestType(Constant.EXPERIENCE_BIDREQUEST_TYPE_CREDITTRANSFER);
        model.addAttribute("pageResult",bidRequestService.queryForPage(qo));
        return "expbidrequest/expbidrequestlist";
    }
}
